<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-collapse [lvMultiExpansion]="'false'" lvType="simple">
  <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="isExpanded">
    <lv-form [formGroup]="formGroup" [lvLabelColon]="false" class="formGroup">
      <lv-form-item>
        <lv-form-label>{{ 'protection_channel_number_label' | i18n }}
          <i lv-icon="aui-icon-help" lv-tooltip="{{ 'protection_fileset_channels_tips_label' | i18n }}"
            lvTooltipTheme="light" class="configform-constraint" lvColorState="true"></i>
        </lv-form-label>
        <lv-form-control [lvErrorTip]="channelsErrorTip">
          <ng-container *ngIf="!isDetail">
            <input lv-input type="text" formControlName="channels" placeholder="1-40" style="width: 140px;" />
          </ng-container>

          <ng-container *ngIf="isDetail">
            {{ protectData?.channels }}
          </ng-container>
        </lv-form-control>
      </lv-form-item>
      <lv-form-item>
        <lv-form-label>{{ 'protection_same_backup_label' | i18n }}
          <i lv-icon="aui-icon-help" lv-tooltip="{{ 'protection_same_backup_tips_label' | i18n }}"
            lvTooltipTheme="light" class="configform-constraint" lvColorState="true"></i>
        </lv-form-label>
        <lv-form-control>
          <ng-container *ngIf="!isDetail">
            <lv-switch formControlName="sameBackup"></lv-switch>
          </ng-container>

          <ng-container *ngIf="isDetail">
            {{protectData?.consistent_backup | textMap: 'Switch_Status'}}
          </ng-container>
        </lv-form-control>
      </lv-form-item>
      <ng-container
        *ngIf="(!isDetail && formGroup.get('sameBackup').value) || (isDetail && protectData?.consistent_backup)">
        <lv-form-item>
          <lv-form-label>
            {{'protection_snapshot_size_percent_label' | i18n}}
            <i lv-icon="aui-icon-help" lv-tooltip="{{ 'protection_snapshot_size_percent_tips_label' | i18n }}"
              lvTooltipTheme="light" class="configform-constraint" lvColorState="true"></i>
          </lv-form-label>
          <lv-form-control [lvErrorTip]='percentErrorTip'>
            <ng-container *ngIf="!isDetail">
              <input lv-input type="text" formControlName="snapshot_size_percent" placeholder="1-100"
                style="width: 140px;">
              <span> %</span>
            </ng-container>
            <ng-container *ngIf="isDetail">
              {{protectData?.snapshot_size_percent || 5}}%
            </ng-container>
          </lv-form-control>
        </lv-form-item>
      </ng-container>
      <lv-form-item>
        <lv-form-label>{{ 'protection_cross_file_system_backup_label' | i18n }}
          <ng-container *ngIf="osType !== dataMap.Fileset_Template_Os_Type.windows.value">
            <i lv-icon="aui-icon-help" lv-tooltip="{{
                'protection_cross_file_system_backup_tips_label' | i18n
              }}" lvTooltipTheme="light" class="configform-constraint" lvColorState="true"></i>
          </ng-container>
          <ng-container *ngIf="osType === dataMap.Fileset_Template_Os_Type.windows.value">
            <i lv-icon="aui-icon-help" lv-tooltip="{{
                'protection_cross_windows_file_system_backup_tips_label' | i18n
              }}" lvTooltipTheme="light" class="configform-constraint" lvColorState="true"></i>
          </ng-container>
        </lv-form-label>
        <lv-form-control>
          <ng-container *ngIf="!isDetail">
            <lv-switch formControlName="crossFileBackup"></lv-switch>
          </ng-container>

          <ng-container *ngIf="isDetail">
            {{protectData?.cross_file_system | textMap: 'Switch_Status'}}
          </ng-container>

        </lv-form-control>
      </lv-form-item>
      <lv-form-item>
        <lv-form-label>
          <ng-container *ngIf="osType !== dataMap.Fileset_Template_Os_Type.windows.value">
            {{ 'protection_backup_nfs_label' | i18n }}
            <i lv-icon="aui-icon-help" lv-tooltip="{{ 'protection_backup_nfs_tips_label' | i18n }}"
              lvTooltipTheme="light" class="configform-constraint" lvColorState="true"></i>
          </ng-container>
          <ng-container *ngIf="osType === dataMap.Fileset_Template_Os_Type.windows.value">
            {{ 'protection_backup_smb_label' | i18n }}
            <i lv-icon="aui-icon-help" lv-tooltip="{{ 'protection_backup_cifs_tips_label' | i18n }}"
              lvTooltipTheme="light" class="configform-constraint" lvColorState="true"></i>
          </ng-container>
        </lv-form-label>
        <lv-form-control>
          <ng-container *ngIf="!isDetail">
            <lv-switch formControlName="nfsBackup"></lv-switch>
          </ng-container>

          <ng-container *ngIf="isDetail">
            {{(osType === dataMap.Fileset_Template_Os_Type.windows.value ? protectData?.backup_smb :
            protectData?.backup_nfs) | textMap: 'Switch_Status'}}
          </ng-container>

        </lv-form-control>
      </lv-form-item>
      <lv-form-item>
        <lv-form-label>{{
          'protection_fileset_sla_advanced_label' | i18n
          }}</lv-form-label>
        <lv-form-control>
          <ng-container *ngIf="!isDetail">
            <lv-switch formControlName="continueBackup"></lv-switch>
          </ng-container>

          <ng-container *ngIf="isDetail">
            {{protectData?.backup_continue_with_files_backup_failed | textMap: 'Switch_Status'}}
          </ng-container>

        </lv-form-control>
      </lv-form-item>
      <lv-form-item *ngIf="osType !== dataMap.Fileset_Template_Os_Type.aix.value">
        <lv-form-label>{{ 'protection_sparse_file_detect_label' | i18n }}
          <i lv-icon="aui-icon-help" lv-tooltip="{{ 'protection_sparse_file_detect_tips_label' | i18n }}"
            lvTooltipTheme="light" class="configform-constraint" lvColorState="true"></i>
        </lv-form-label>
        <lv-form-control>
          <ng-container *ngIf="!isDetail">
            <lv-switch formControlName="sparseFileDetect"></lv-switch>
          </ng-container>

          <ng-container *ngIf="isDetail">
            {{protectData?.sparse_file_detection | textMap: 'Switch_Status'}}
          </ng-container>

        </lv-form-control>
      </lv-form-item>
      <lv-form-item *ngIf="!batchModify">
        <lv-form-label>{{ 'protection_small_file_aggregation_label' | i18n }}
          <i lv-icon="aui-icon-help" lv-tooltip="{{
              'protection_small_file_aggregation_tips_label' | i18n
            }}" lvTooltipTheme="light" class="configform-constraint" lvColorState="true"></i>
        </lv-form-label>
        <lv-form-control>
          <ng-container *ngIf="!isDetail">
            <lv-switch formControlName="smallFile"
              [lvDisabled]="isModified || disableSmallFile || hasRansomware"></lv-switch>
          </ng-container>
          <ng-container *ngIf="isDetail">
            {{enableSmallFile | textMap: 'Switch_Status'}}
          </ng-container>
          <ng-container *ngIf="enableSmallFile">
            <div class="tips-info">
              <i lv-icon="lv-icon-status-info" lvColorState="true" class="type-icon"></i>
              <span>
                {{'protection_aggregation_tip_label' | i18n}}
              </span>
            </div>
            <lv-form-item>
              <lv-form-label>{{
                'protection_small_file_size_label' | i18n
                }}</lv-form-label>
              <lv-form-control>
                <ng-container *ngIf="!isDetail">
                  <ng-container *ngIf="isModified">
                    <div>
                      {{
                      resourceData?.protectedObject?.extParameters
                      ?.aggregation_file_size + ' KB' | nil
                      }}
                    </div>
                  </ng-container>
                  <ng-container *ngIf="!isModified">
                    <lv-radio-group formControlName="fileSize" [lvGroupName]="'fileSize'" [lvDisabled]="isModified">
                      <lv-group>
                        <lv-radio [lvViewType]="'button'" [lvValue]="dataMap.Small_File_Size.small.value">{{
                          dataMap.Small_File_Size.small.label }}</lv-radio>
                        <lv-radio [lvViewType]="'button'" [lvValue]="dataMap.Small_File_Size.normal.value">
                          {{ dataMap.Small_File_Size.normal.label }}</lv-radio>
                        <lv-radio [lvViewType]="'button'" [lvValue]="dataMap.Small_File_Size.large.value">{{
                          dataMap.Small_File_Size.large.label }}</lv-radio>
                        <lv-radio [lvViewType]="'button'" [lvValue]="dataMap.Small_File_Size.xlarge.value">
                          {{ dataMap.Small_File_Size.xlarge.label }}</lv-radio>
                      </lv-group>
                    </lv-radio-group>
                  </ng-container>
                </ng-container>

                <ng-container *ngIf="isDetail">
                  <div>
                    {{
                    protectData?.aggregation_file_size + ' KB' | nil
                    }}
                  </div>
                </ng-container>
              </lv-form-control>
            </lv-form-item>
            <lv-form-item>
              <lv-form-label>{{
                'protection_file_max_size_label' | i18n
                }}</lv-form-label>
              <lv-form-control>
                <ng-container *ngIf="!isDetail">
                  <ng-container *ngIf="isModified">
                    <div>
                      {{
                      resourceData?.protectedObject?.extParameters
                      ?.aggregation_file_max_size + ' KB' | nil
                      }}
                    </div>
                  </ng-container>
                  <ng-container *ngIf="!isModified">
                    <lv-radio-group formControlName="maxFileSize" [lvGroupName]="'maxFileSize'"
                      [lvDisabled]="isModified">
                      <lv-group>
                        <lv-radio [lvViewType]="'button'" [lvValue]="dataMap.Small_File_Size.small.value">{{
                          dataMap.Small_File_Size.small.label }}</lv-radio>
                        <lv-radio [lvViewType]="'button'" [lvValue]="dataMap.Small_File_Size.normal.value">
                          {{ dataMap.Small_File_Size.normal.label }}</lv-radio>
                        <lv-radio [lvViewType]="'button'" [lvValue]="dataMap.Small_File_Size.large.value">{{
                          dataMap.Small_File_Size.large.label }}</lv-radio>
                        <lv-radio [lvViewType]="'button'" [lvValue]="dataMap.Small_File_Size.xlarge.value">
                          {{ dataMap.Small_File_Size.xlarge.label }}</lv-radio>
                      </lv-group>
                    </lv-radio-group>
                  </ng-container>
                </ng-container>

                <ng-container *ngIf="isDetail">
                  <div>
                    {{
                    protectData?.aggregation_file_max_size + ' KB' | nil
                    }}
                  </div>
                </ng-container>
              </lv-form-control>
            </lv-form-item>
          </ng-container>
        </lv-form-control>
      </lv-form-item>
      <lv-form-item>
        <lv-form-label>{{ 'protection_script_label' | i18n }}
          <i lv-icon="aui-icon-help" [lv-tooltip]="scriptTips" lvTooltipTheme="light" class="configform-constraint"
            lvColorState="true"></i>
        </lv-form-label>
        <lv-form-control>
          <ng-container *ngIf="!isDetail">
            <lv-switch formControlName="script"></lv-switch>
          </ng-container>
          <ng-container *ngIf="isDetail">
            {{enableScript | textMap: 'Switch_Status'}}
          </ng-container>

          <ng-container *ngIf="enableScript">
            <lv-form-item>
              <lv-form-label>
                {{ 'protection_protect_pre_script_label' | i18n }}
              </lv-form-label>
              <lv-form-control [lvErrorTip]="scriptErrorTip">
                <ng-container *ngIf="!isDetail">
                  <input lv-input type="text" formControlName="preScript" [placeholder]="scriptPlaceholder"
                    style="width: 360px;" />
                </ng-container>
                <ng-container *ngIf="isDetail">
                  <div>{{ protectData?.pre_script | nil }}</div>
                </ng-container>
              </lv-form-control>
            </lv-form-item>
            <lv-form-item>
              <lv-form-label>
                {{ 'protection_protect_post_script_label' | i18n }}
              </lv-form-label>
              <lv-form-control [lvErrorTip]="scriptErrorTip">
                <ng-container *ngIf="!isDetail">
                  <input lv-input type="text" formControlName="postScript" [placeholder]="scriptPlaceholder"
                    style="width: 360px;" />
                </ng-container>
                <ng-container *ngIf="isDetail">
                  <div>{{ protectData?.post_script | nil }}</div>
                </ng-container>
              </lv-form-control>
            </lv-form-item>
            <lv-form-item>
              <lv-form-label>
                {{ 'protection_protect_fail_script_label' | i18n }}
              </lv-form-label>
              <lv-form-control [lvErrorTip]="scriptErrorTip">
                <ng-container *ngIf="!isDetail">
                  <input lv-input type="text" formControlName="executeScript" [placeholder]="scriptPlaceholder"
                    style="width: 360px;" />
                </ng-container>

                <ng-container *ngIf="isDetail">
                  <div>{{ protectData?.failed_script | nil }}</div>
                </ng-container>

              </lv-form-control>
            </lv-form-item>
          </ng-container>
        </lv-form-control>
      </lv-form-item>
    </lv-form>
    <!-- 防勒索副本设置参数 -->
    <ng-container>
      <aui-copy-limit-advanced-parameter [formGroup]="formGroup"
        [data]="resourceData"></aui-copy-limit-advanced-parameter>
    </ng-container>
    <!-- 修改索引设置 -->
    <ng-container *ngIf="!batchModify || isDetail">
      <aui-update-index [formGroup]="formGroup" [isDetail]="isDetail" [protectData]="protectData"
        [extParams]="extParams"></aui-update-index>
    </ng-container>
  </lv-collapse-panel>
</lv-collapse>

<ng-template #titleTpl>
  <lv-group lvGutter="8px">
    <span class="aui-h3">{{
      'common_advanced_label' | i18n
      }}</span>
  </lv-group>
</ng-template>